﻿using System.ComponentModel;

using DaprPlus.EntityFrameworkCore;

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;


namespace Todos.Infrastructure.EntityFrameworkCore;

[Description("Todos-EFCore模块")]
public class SqlServerEntityFrameworkCoreModule:EntityFrameworkCoreModuleBase
{
    public override IServiceCollection AddServices(IServiceCollection services)
    {
        services.AddDbContext<TodosDbContext>((builder, options) =>
        {
            builder.UseSqlServer(options.ConnectionString, opt =>
            {
                opt.MigrationsAssembly(options.MigrationsAssembly ?? Assembly.GetName().Name);
            });
        });
        
        return base.AddServices(services);
    }

    public override Task UseModule(IServiceProvider provider)
    {
        provider.CheckAndMigration<TodosDbContext>();
        return base.UseModule(provider);
    }
}
